package com.project.service.impl;

import com.project.bean.ClientBean;
import com.project.bean.StatMonthSellBean;
import com.project.mapper.IStatMonthSellMapper;
import com.project.service.IStatMonthSellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatMonthSellServiceImpl implements IStatMonthSellService {

    @Autowired
    private IStatMonthSellMapper statMonthSellMapper;

    /**
     * 按照年份统计每个月，每个商品类别的销售金额
     *
     * @param year 年份
     * @return 月销售统计对象
     */
    @Override
    public List<StatMonthSellBean> findByYear(String year) {
//        return statMonthSellMapper.findByMonth(year);

        List<StatMonthSellBean> clientBeans = statMonthSellMapper.findByYer(year);
        List<StatMonthSellBean> clientBean = new ArrayList<>();
        for (StatMonthSellBean c : clientBeans) {
            if (c != null) {
                clientBean.add(c);
            }
        }
        return clientBean;
    }

    /**
     * 查询所有的销售年份
     *
     * @return 年份集合
     */
    @Override
    public List<Integer> findYer() {
        return statMonthSellMapper.findYear();
    }
}
